<?php 
function com_install(){
  global $database;
	$uploads_dir = "components/com_bookman/uploads/";
	chmod( $uploads_dir, 0777 );
	chmod( $uploads_dir."thumbnails/", 0777 );
	chmod( $uploads_dir."original_imgs/", 0777 );

  $database->setQuery( "SELECT id FROM #__components WHERE admin_menu_link = 'option=com_bookman'" );
  $id = $database->loadResult();

  //add new admin menu images
  $database->setQuery("
    UPDATE
      #__components
    SET
      admin_menu_img = '../administrator/components/com_bookman/images/units.gif'
    WHERE
      id='".$id."'");
  $database->query();
  
	$database->setQuery("INSERT INTO `#__bookman_set_letters` (`id`, `identifier`, `msg_subject`, `msg_body`) VALUES
		(1, 'Confirmation', 'Subject', 'Text'),
		(2, 'CC Declined', 'Subject', 'Text'),
		(3, 'Directions', 'Subject', 'Text'),
		(4, 'SD Request', 'Subject', 'Text'),
		(5, 'SD Return', 'Subject', 'Text'),
		(6, 'Owner Check', 'Subject', 'Text'),
		(7, 'Letter07', 'Subject', 'text'),
		(8, 'Letter08', 'Subject', 'Text'),
		(9, 'Letter09', 'Subject', 'Text'),
		(10, 'Letter10', 'Subject', 'Text')
		");
	$database->query();
	
	$sql = "SELECT module FROM #__modules WHERE module='mod_bookman_search'";
	$database->setQuery($sql);
	$rows = $database->loadObjectList();
	if (isset($rows[0]->module)) {
			echo "<img src='".$mosConfig_live_site."/administrator/images/publish_x.png'> (Search module already installed)<br>";
	} else {
		$database->setQuery( "INSERT INTO `#__modules` (`title`, `content`, `ordering`, `position`, `checked_out`, `checked_out_time`, `published`, `module`, `numnews`, `access`, `showtitle`, `params`, `iscore`, `client_id`) 
			VALUES ('Booking Manager Search', '', 2, 'right', 0, '0000-00-00 00:00:00', 1, 'mod_bookman_search', 0, 0, 0, '', 0, 0);");
		$database->query();
		$moduleID = $database->insertid();
		$database->setQuery( "INSERT INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES ($moduleID, 0);");
		$database->query();
		$modulestate1 = @rename( $mosConfig_absolute_path. "/administrator/components/com_bookman/module/mod_bookman_search.php", $mosConfig_absolute_path."/modules/mod_bookman_search.php");
		if ($modulestate1) {
			echo "<img src='".$mosConfig_live_site."/administrator/images/tick.png'> The search module has been installed<br>";
		}
		else echo "<img src='".$mosConfig_live_site."/administrator/images/publish_x.png'> The search module could not be installed<br>";
	}
	?>
	<h1>Welcome to Booking Manager</h1><br>
	If the module installation failed than install it manually or contact us.<br>
	Configure your setting in the configuration section.
<?php }?>